package com.choosefine.it.team.service.Impl;


import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.team.dao.PersonalCenterMapper;
import com.choosefine.it.team.model.PersonalCenter;
import com.choosefine.it.team.model.vo.PersonInfoDetailVO;
import com.choosefine.it.team.service.TeamHomePageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Service("teamHomePageService")
public class TeamHomePageServiceImpl implements TeamHomePageService {
	@Autowired
	MongoTemplate mongoTemplate;

	@Autowired
	private PersonalCenterMapper personalCenterMapper;

	@Override
	public PersonalCenter getPersonalCenter(String userCode) {

		return personalCenterMapper.selectByUserCode(userCode);
	}

	@Override
	public PersonInfoDetailVO getPersonDetailInfoByUserCode(String userCode) {
		PersonInfoDetailVO p = null;
			p=mongoTemplate.findOne(new Query(Criteria.where("userCode").is(userCode)),PersonInfoDetailVO.class);
		if(p != null){
			p.setStayYear(DateUtils.getworkeryear(p.getCtime()));
			p.setUserRole(personalCenterMapper.getRoleNameById(p.getUserType()));
			}
		return p;
	}
}
